/*
 * URL.h
 *
 *  Created on: 2010-6-19
 *      Author: SW
 */

#ifndef URL_H_
#define URL_H_
#include <string>
#include <cstdlib>
using namespace std;

namespace HA {

class URL {
public:
	/**
	 * Create a URL from the specified string.
	 * @param spec The string to parse as URL.
	 */
	URL(const string& spec);

	/**
	 * Get the hostname part of this URL.
	 * @return The hostname part of this URL.
	 */
	string getHostName() const {
		return hostname;
	}

	/**
	 * Get the fragment part of this URL.
	 * @return The fragment part of this URL.
	 */
	string getFragment() const {
		return fragment;
	}


	/**
	 * Get the parameters part of this URL.
	 * @return The parameters of this URL.
	 */
	string getParameters() const {
		return parameters;
	}

	/**
	 * Get the path part of this URL.
	 * @return The path part of this URL.
	 */
	string getPath() const {
		return path;
	}

	/**
	 * Get the port part of this URL.
	 * @return The port part of this URL.
	 */
	unsigned int getPort() const {
		return port;
	}

	/**
	 * Get the protocol part of this URL.
	 * @return The protocol part of this URL.
	 */
	string getProtocol() const {
		return protocol;
	}

	/**
	 * Get the query part of this URL.
	 * @return The query part of this URL.
	 */
	string getQuery() const {
		return query;
	}

private:
	void parseURL(const string& spec);
private:
	string protocol;
	string hostname;
	string path;
	string parameters;
	string query;
	string fragment;
	unsigned int port;
};

}

#endif /* URL_H_ */
